package com.xauto.pioneer.appuser.model;

import android.content.Context;

import net.tsz.afinal.FinalDb;
import net.tsz.afinal.annotation.sqlite.Id;
import net.tsz.afinal.annotation.sqlite.Table;

import org.json.JSONObject;

/**日期数据模型
 * Created by Ellis.Li on 2017/5/12.
 */
@Table(name = "table_setting_date")
public class SettingDate extends BaseModel<SettingDate> {

    /**日期配置ID*/
    @Id(column = "setting_date_id")
    public String setting_date_id;
    /** 当前时间*/
    public String current_date;
    /** 开始时间*/
    public String date_start_time;
    /** 结束时间*/
    public String date_end_time;
    /** 当前日期类型(1-平日/2-周末/3-节假期)*/
    public String date_type;

    @Override
    public SettingDate parse(JSONObject jsonObject) {
        if(jsonObject != null) {
            date_start_time = jsonObject.optString("date_start_time");
            date_end_time = jsonObject.optString("date_end_time");
            date_type = jsonObject.optString("date_type");
            current_date = jsonObject.optString("current_date");
            setting_date_id = jsonObject.optString("setting_date_id");
            return this;
        }
        return null;
    }
    @Override
    public boolean equals(Object o) {
        if (((SettingDate)o).setting_date_id.equals(setting_date_id)){
            return true;
        }
        return false;
    }

    public void saveDb(Context mContext, SettingDate billRule) {
        FinalDb finalDb = FinalDb.create(mContext);
        finalDb.deleteByWhere(SettingDate.class, "setting_date_id = \""+billRule.setting_date_id+"\"");
        finalDb.save(billRule);
    }
}
